package com.jfire.orm.field.impl;

import java.lang.reflect.Field;
import sun.misc.Unsafe;
import com.jfire.baseutil.StringUtil;
import com.jfire.baseutil.reflect.ReflectUtil;
import com.jfire.orm.annotation.Column;
import com.jfire.orm.field.MapField;

/**
 * 基础CURD操作映射的抽象属性类
 * 
 * @author linbin
 * 
 */
@SuppressWarnings("restriction")
public abstract class AbstractMapField implements MapField
{
    protected long          offset;
    protected String        dbColName;
    protected static Unsafe unsafe = ReflectUtil.getUnsafe();
    
    public AbstractMapField(Field field)
    {
        offset = unsafe.objectFieldOffset(field);
        dbColName = field.getName();
        if (field.isAnnotationPresent(Column.class) && StringUtil.isNotBlank(field.getAnnotation(Column.class).name()))
        {
            dbColName = field.getAnnotation(Column.class).name();
        }
    }
    
    @Override
    public String getColName()
    {
        return dbColName;
    }
    
}
